package com.zfcoding.mqkafka.handler;


import com.zfcoding.mqkafka.constants.KafkaConsts;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.support.Acknowledgment;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class MessageHandler {

@KafkaListener(topics = KafkaConsts.TOPIC_TEST,containerFactory = "ackContainerFactory")
    public void handleMessage(ConsumerRecord record, Acknowledgment acknowledgment){
        try {
            String message = (String) record.value();
            log.info("收到消息 - {}",message);
        }catch(Exception ex){
            log.error(ex.getMessage(),ex);
        }finally    {
            acknowledgment.acknowledge();
        }

    }
}
